package at.ac.tuwien.sepm.s2011.e0208329.services;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;
//import java.util.Iterator;

import at.ac.tuwien.sepm.s2011.e0208329.dao.DAOFactoryImpl;
//import at.ac.tuwien.sepm.s2011.e0208329.dao.DienstleistungDAOImpl;
//import at.ac.tuwien.sepm.s2011.e0208329.dao.OrderDAO;
//import at.ac.tuwien.sepm.s2011.e0208329.dao.OrderDAOImpl;
import at.ac.tuwien.sepm.s2011.e0208329.dao.RechnungDAOImpl;
//import at.ac.tuwien.sepm.s2011.e0208329.db.DatabaseManager;
//import at.ac.tuwien.sepm.s2011.e0208329.domain.Dienstleistung;
import at.ac.tuwien.sepm.s2011.e0208329.domain.Rechnung;

/**
 * this class perform the service-calling to RechnungDAO,OderDAO
 * offer the functions to handle Bill-Service
 * @author YAN Kun
 *
 */
public class MyBillServiceImpl implements MyBillService {
	private RechnungDAOImpl billDAO;
	//private OrderDAO orderDAO; 
	//private DatabaseManager dbm;
	public static MyBillServiceImpl refBillService;
	
	public MyBillServiceImpl() { // Initialize
		super();
		//dbm = DatabaseManager.getDatabaseManager();
		billDAO = DAOFactoryImpl.getDAOFactory().getBillDAO();
		//orderDAO = DAOFactoryImpl.getDAOFactory().getOrderDAO();
	}

	/**
	 * this method should save a bill, exclusive make orders
	 */
	@Override
	public Rechnung createBill(Rechnung myBill) throws SQLException {
		billDAO.insertBill(myBill);
		return myBill;
	}

	@Override
	public ArrayList<Rechnung> getBills() throws SQLException { // call RechnungDAO.getAllBills(), to read all bills from DB
		return billDAO.getAllBills();
	}
	
	public static MyBillServiceImpl getInstance() { //getter
	    if(refBillService == null){
	    	refBillService = new MyBillServiceImpl();
	    }
	    return refBillService;
	}

	@Override
	public Map<Integer, Integer> getAllServiceIDForBill(int billID) throws SQLException {
		return billDAO.getAllServiceIDForBill(billID); // call method from RechnungDAO to get 
		//all Service's ID and the amount from table 'rechnungitem' which has the same specified Bill ID
	}





}
